package com.ssyt.hiring.web.dao;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Repository;

import com.ssyt.cdp.common.BaseDao;
import com.ssyt.hiring.entity.TalentEntity;

@Repository
public class TalentDao extends BaseDao<TalentEntity, Integer> {

	/**
	 * 求职者登录
	 * 
	 * @return
	 */
	public TalentEntity talentLogin(TalentEntity talent) {

		String hql = "from TalentEntity where code=? and password=?";
		return uniqueEntityByHql(hql, talent.getCode(), talent.getPassword());
	}

	/**
	 * 求职者注册
	 * 
	 * @return
	 */
	public void talentRegister(TalentEntity talent) {
		save(talent);
	}

	/**
	 * 求职者注销
	 * 
	 * @return
	 */
	public void logout() {

		ServletActionContext.getRequest().getSession().invalidate();

	}

	/**
	 * 查询求职者信息
	 * 
	 * @return
	 */
	public TalentEntity getTalentInfo(int talentId) {
		String hql = "from TalentEntity where id =?";
		return uniqueEntityByHql(hql, talentId);
	}

	/**
	 * 求职者资料修改
	 */
	public void talentUpdate(TalentEntity talent) {
		update(talent);
	}

	/**
	 * Ajax查询所有的求职者信息
	 */
	public TalentEntity getTalentInfoByAjax(int resumeId, int talentId) {
		String hql = "select new TalentEntity(t.name,t.phone,t.email,t.age,t.gender,t.interestPositions,r.workExperience as workExperience,r.projectExperience as projectExperience) from ApplicationEntity a,ResumeEntity r,TalentEntity t WHERE a.resumeId=r.id and r.talentId=t.id and a.resumeId=? and r.talentId=? ";
		return uniqueEntityByHql(hql, resumeId, talentId);
	}

	public boolean checkTalentName(String code) {
		String hql = "from TalentEntity where code=?";
		TalentEntity talent = uniqueEntityByHql(hql, code);
		if (talent != null) {
			return false;
		}
		return true;
	}
}